package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.*;
import cn.wolfcode.trip.base.mapper.StrategyCatalogMapper;
import cn.wolfcode.trip.base.mapper.StrategyContentMapper;
import cn.wolfcode.trip.base.mapper.StrategyMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.StrategyQueryObject;
import cn.wolfcode.trip.base.service.IStrategyCatalogService;
import cn.wolfcode.trip.base.service.IStrategyDetailService;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.service.ITravelService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StrategyServiceImpl implements IStrategyService {
    @Autowired
    private StrategyMapper strategyMapper;

    @Autowired
    private StrategyContentMapper contentMapper;

    @Autowired
    private StrategyCatalogMapper catalogMapper;

    @Autowired
    private ITravelService travelService;

    @Autowired
    private IStrategyCatalogService catalogService;

    @Override
    public void save(Strategy strategy) {
        strategyMapper.insert(strategy);
    }

    @Override
    public PageInfo query(StrategyQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Strategy> list = strategyMapper.queryForList(qo);
        return new PageInfo(list);
    }


    @Override
    public void delete(Long id) {
        strategyMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void saveOrUpdate(Strategy strategy) {
        if (strategy.getId() != null) {
            strategyMapper.updateByPrimaryKey(strategy);
        }else {
            strategyMapper.insert(strategy);
        }
    }

    @Override
    public StrategyContent getContetByDetailId(Long detailId) {
        return contentMapper.selectByPrimaryKey(detailId);
    }

    @Override
    public PageInfo selectHot(StrategyQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Strategy> list = strategyMapper.selectHot(qo);
        return new PageInfo(list);
    }

    @Override
    public List<StrategyCatalog> getCatalogByStrategyId(Long strategyId) {
        return catalogMapper.selectCatalogByStrategyId(strategyId);
    }

    @Override
    public List<Travel> getTravelsByStrategyId(Long strategyId) {
        return travelService.selectTravelsBystrategyId(strategyId);
    }

    @Override
    public List<Tag> queryTagsByStrategyId(Long strategyId) {
        return strategyMapper.queryTagsByStrategyId(strategyId);
    }

    @Override
    public Integer getStrategyCount(Long strategyId) {
        return strategyMapper.selectStrategyCount(strategyId);
    }

    @Override
    public Integer getStrategyStatus(Long userId, Long strategyId) {
        return strategyMapper.selectStrategyStatus(userId,strategyId);
    }

    @Override
    public List<Strategy> getStrategysByUserId(Long userId) {
        return strategyMapper.selectStrategy(userId);
    }

    @Override
    public List<Strategy> selectAll() {
        return strategyMapper.selectAll();
    }

    @Override
    public void update(Strategy strategy) {
        strategyMapper.updateByPrimaryKey(strategy);
    }

    @Override
    public Strategy get(Long id) {
        return strategyMapper.selectByPrimaryKey(id);
    }

}
